package com.ldu.util;

import org.springframework.beans.BeanUtils;

/**
 * Created by suclogger on 16/5/23.
 */
public class BeanUtil {

    public static <T> T createCloneBean(Object obi, Class<T> destClaz) {
        try {
            T destObj = destClaz.newInstance();
            BeanUtils.copyProperties(obi, destObj);
            return destObj;
        } catch (Exception e) {
            throw new RuntimeException("Copy prop error.", e);
        }
    }

    public static Object copyPorp2DO(Class<?> destClaz, Object obi) throws RuntimeException {
        try {
            Object destObj = destClaz.newInstance();
            BeanUtils.copyProperties(obi, destObj);
            return destObj;
        } catch (Exception e) {
            throw new RuntimeException("Copy prop error.", e);
        }
    }

    public static void copyProperties(Object originObj, Object destObj) {
        try {
            BeanUtils.copyProperties(originObj, destObj);
        } catch (Exception e) {
            throw new RuntimeException("Copy prop error.", e);
        }
    }

}
